﻿//------------------------------------------------------------------------------------------------- 
// <copyright file="ConnectWebParts.cs" company="Collaboris Ltd.">
//   Copyright (c) Collaboris Ltd. All rights Reserved.
// </copyright>
// <summary>Creates a new SPWebApplication.</summary>
//-------------------------------------------------------------------------------------------------
namespace Collaboris.Saf.Actions.Wss.WebPart
{
    using Engine;

    using Entities;

    using SharePoint.Wss.Attributes;
    using SharePoint.Wss.WebParts;

    [CollaborisClass(
        Title = "Connect WebPart",
        ReleaseStatus = ReleaseStatus.Development,
        DisableDocumentation = false,
        ContactAuthorEmail = "Support@Collaboris.co.uk",
        Summary = "This action allows 2 web parts (provider and consumer) to " + 
                  "be connected on a particular web part page.",
        ClassGuid = "{156E17A5-A7BA-4e1f-8A48-1BC341A7C664}"
        )
    ]
    public class ConnectWebParts : WSSActionBase<WebPartConnectionInfo>
    {

        /// <summary>
        /// Does the action.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        protected override ProcessStatus DoAction(SafContext context, WebPartConnectionInfo entity)
        {
            this.Trace.TraceMethodStart("DoAction");

            
            // now lets go connect em up.
            SPWebPartHelper.ConnectWebParts(
                                    TargetWeb,
                                    entity.WebPartPageRelativeUrl,
                                    entity.PersonalizationScope,
                                    entity.ProviderWebPartId,
                                    entity.ConsumerWebPartId,
                                    entity.ProviderConnectionId,
                                    entity.ConsumerConnectionId, entity.WebPartTransformer);

            this.Trace.TraceMethodEnd("DoAction");

            return ProcessStatus.Success;
        }
    }
}